<div class="pagebody">

	<form name="add_invoice" method="post" action="{$FORM_ACTION}">
	<input type="hidden" name="invoiceid" id="invoiceid" value="{$INVOICE_ID}">
	<table width="100%" border="0" id="invoicetable">
		<tr>
			<td>Bill To
				<select name="inv_client" id="inv_client"/>
					<option value="">Choose</option>
					{foreach from=$CLIENT_OPTIONS key=k item=client}
						{if $client->id == $SELECTED_CLIENT}
							<option value="{$client->id}" selected="selected">{$client->BusinessName}</option>
						{else}
							<option value="{$client->id}">{$client->BusinessName}</option>
						{/if}
					{/foreach}
				</select>
			</td>
			<td>Repeat</td>
			<td>Until</td>
			<td>Payment Terms</td>
			<td>Date</td>
			<td>Due Date</td>
			<td>Invoice Number</td>
		</tr>

		<tr rowspan="8" valign="top">
			<td valign="top"><textarea name="billto" id="billto" rows="5" cols="30" readonly="readonly"></textarea></td>
			<td><select name="repeat">
					<option value="">Choose</option>
					<option value="Daily">Daily</option>
					<option value="Weekly">Weekly</option>
					<option value="Monthly">Monthly</option>
				</select></td>
			<td><input type="text" size="8" name="until" /><img src="{$SITE_WWW}img/cal.png" border="0" onClick="cal1xx.select(document.forms[0].until,'anchor3xx','dd/MM/yyyy'); return false;" title="cal1xx.select(document.forms[0].until,'anchor3xx','MM/dd/yyyy'); return false;" name="anchor3xx" id="anchor3xx"/></td>
			<td><select name="terms">
					<option value="">Choose</option>
					{foreach from=$PAYMENT_TERMS key=key item=term}
						<option value="{$key}">{$term}</option>
					{/foreach}
				</select><img src="img/edit_add.png" border="0" id="addTerms" /></td>
			<td><input type="text" size="8" name="inv_date" value="{$INVOICE_DATE}" /><img src="{$SITE_WWW}img/cal.png" border="0" onClick="cal1xx.select(document.forms[0].inv_date,'anchor1xx','dd/MM/yyyy'); return false;" TITLE="cal1xx.select(document.forms[0].inv_date,'anchor1xx','MM/dd/yyyy'); return false;" name="anchor1xx" id="anchor1xx" /></td>
			<td><input type="text" size="8" name="inv_duedate" value="{$INVOICE_DUEDATE}" /><img src="{$SITE_WWW}img/cal.png" border="0" onClick="cal1xx.select(document.forms[0].inv_duedate,'anchor2xx','dd/MM/yyyy'); return false;" TITLE="cal1xx.select(document.forms[0].inv_duedate,'anchor2xx','MM/dd/yyyy'); return false;" name="anchor2xx" id="anchor2xx" /></td>
			<td><input type="text" size="8" name="inv_invoicenumber" value="{$INVOICE_NUMBER}" /></td>
		</tr>
	</table>

	<table>
		<tr>
			<td width="15%">Item Select</td>
			<td width="35%">Item Description</td>
			<td width="5%">Qty</td>
			<td>Amount Each</td>
			<td>Tax</td>
			<td>Total</td>
		</tr>

		{assign var='rowcount' value='0'}
		{foreach from=$INVOICE_ITEMS key=k item=inv_item}
		<tr id="{$rowcount}">
			<td>
			<select name="item_itemid[{$inv_item->InvoiceItemID}]" id="item_itemid[{$inv_item->InvoiceItemID}]">
			<option value="">Choose</option>
			{assign var='lastcat' value=''}

			{foreach from=$AVAILABLE_ITEMS key=k item=i}
				{if $i->CategoryID != $lastcat}
					<option value="">{$i->CategoryName}</option>
				{/if}
				{if $inv_item->ItemID == $i->id}
					<option value="{$i->id}" selected="selected">{$i->Name}</option>
				{else}
					<option value="{$i->id}" >{$i->Name}</option>
				{/if}
				{assign var='lastcat' value=$i->CategoryID}
			{/foreach}

			</select></td>
			<td><input type="text" id="item_description[{$inv_item->InvoiceItemID}]" name="item_description[{$inv_item->InvoiceItemID}]" value="{$inv_item->Description}" /></td>
			<td><input type="text" id="item_quantity[{$inv_item->InvoiceItemID}]" name="item_quantity[{$inv_item->InvoiceItemID}]" value="{$inv_item->Quantity}" /></td>
			<td><input type="text" id="item_amounteach[{$inv_item->InvoiceItemID}]" name="item_amounteach[{$inv_item->InvoiceItemID}]" value="{$inv_item->AmountEach}" /></td>
			<td><input type="text" id="item_taxamount[{$inv_item->InvoiceItemID}]" name="item_taxamount[{$inv_item->InvoiceItemID}]" value="{$inv_item->TaxAmount}" /></td>
			<td><input type="text" id="rowtotal[{$inv_item->InvoiceItemID}]" name="rowtotal[{$inv_item->InvoiceItemID}]" value="{$inv_item->RowTotal}" /></td>
		</tr>
		{assign var='rowcount' value=$rowcount+1}
		{/foreach}

		{assign var='rowcount' value=$rowcount+1}
		<tr id="{$rowcount}">
			<td>
			<select name="item_itemid[New][0]" id="item_itemid[New][0]">
			<option value="">Choose</option>
			{assign var='lastcat' value=''}

			{foreach from=$AVAILABLE_ITEMS key=k item=i}
				{if $i->CategoryID != $lastcat}
					<option value="">{$i->CategoryName}</option>
				{/if}
				<option value="{$i->id}">{$i->Name}</option>
				{assign var='lastcat' value=$i->CategoryID}
			{/foreach}

			</select></td>
			<td><input type="text" id="item_description[New][0]" name="item_description[New][0]" /></td>
			<td><input type="text" id="item_quantity[New][0]" name="item_quantity[New][0]" /></td>
			<td><input type="text" id="item_amounteach[New][0]" name="item_amounteach[New][0]" /></td>
			<td><input type="text" id="item_taxamount[New][0]" name="item_taxamount[New][0]" /></td>
			<td><input type="text" id="rowtotal[New][0]" name="rowtotal[New][0]" /></td>
		</tr>



	</table>

	<table width="100%" id="invoiceoptionstable">
		<tr>
			<td><label for "email">Email to Client: <input type="checkbox" name="email" checked="checked" /></label></td>
			<td><input type="button" id="Export" value="Export" onclick="return exportAs(this);" /> <input type="submit" id="submit" name ="submit" value="Save" /></td>
		</tr>
	</table>
	</form>
</div>

<div id="exportas" class="exportas">
Export As;<br />
<form name="exportas" action="admin_invoices_export.php" target="_blank">
<table>
    <tr>
        <td>
        	<img src="{$SITE_WWW}img/spreadsheet_document.png" alt="CSV" title="CSV" /><input type="radio" name="exportas" value="csv" /><br />
			<img src="{$SITE_WWW}img/pdf.png"  alt="PDF" title="PDF" /> <input type="radio" name="exportas" value="pdf" /><br />
        </td>
        <td>
        	<input type="submit" name="submit" value="go" /></form>
        </td>
    </tr>
</table>
</div>

<div id="myPanel"> 
	<div class="hd">Add Payment Terms</div> 
	<div class="bd">
		<form name="paymentTerms" action="{$FORM_ACTION}" method="POST">
			<input type="text" name="addTerm" id="addTerm" size="30" /><br />
			<input type="submit" name="submit" value="Add" />
		</form>
	</div>
</div>